{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
    <form class="layui-form gg-form-bar border-x border-t" lay-filter="barsearchform">

        <div class="layui-input-inline" style="width:240px;">
            <input type="text" name="keywords" placeholder="输入资质名称" class="layui-input" autocomplete="off"/>
        </div>
        <div class="layui-input-inline" style="width:150px;">
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i
                    class="layui-icon layui-icon-search mr-1"></i>搜索
            </button>
            <button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>
        </div>
    </form>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <span class="layui-btn layui-btn-sm" title="添加" lay-event="add">+ 添加</span>
    </div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];
    // {
    //     field: 'check_status', title: '状态', align: 'center', width: 200, templet: function (d) {
    //     var html = '<span class="layui-btn layui-btn-xs layui-bg-' + d.check_status + '">' + d.status_name + '</span>';
    //     return html;
    // }
    // },
    function gouguInit() {
        var table = layui.table, tool = layui.tool, form = layui.form;
        layui.pageTable = table.render({
            elem: '#test',
            title: '项目列表',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', {title: '导出EXCEL', layEvent: 'LAYTABLE_EXCEL', icon: 'layui-icon-export'}],
            url: "/busine/businetransfer/index", //数据接口
            cellMinWidth: 80,
            page: true, //开启分页
            limit: 20,
            cols: [
                [ //表头
                    {
                        field: 'id',
                        title: '编号',
                        align: 'center',
                        width: 80,
                        templet: function (d) {
                            return d.LAY_INDEX+1
                        }
                    }, {
                    field: 'cert_name',
                    title: '资质名称',
                    width: 300
                }, {
                    field: 'buy_company',
                    title: '购买方企业',
                    align: 'center',
                    width: 200
                }, {
                    field: 'transfer_company',
                    title: '转让方企业',
                    align: 'center',
                    width: 200
                }, {
                    field: 'sign_name',
                    title: '签单人',
                    align: 'center',
                    width: 200
                },  {
                    field: 'status_name', title: '状态', align: 'center', width: 100, templet: function (d) {
                        var html = '<span class="black">待上报</span>';
                        if (d.check_status == 1) {
                            html = '<span class="blue">审核中</span>';
                        }
                        else if (d.check_status == 2) {
                            html = '<span class="green">审核通过</span>';
                        }
                        else if (d.check_status == 3) {
                            html = '<span class="red">审核不通过</span>';
                        }
                        else if (d.check_status == 4) {
                            html = '<span class="red">已撤销</span>';
                        }
                        else if (d.check_status == 5) {
                            html = '<span class="green">已开具</span>';
                        }
                        else if (d.check_status == 10) {
                            html = '<span class="yellow">已作废</span>';
                        }
                        return html;
                    }
                }, {
                    field: 'right',
                    title: '操作',
                    align: 'center',
                    templet: function (d) {
                        var html = '<div class="layui-btn-group">';
                        var btn1 = '';
                        var btn2 = '';
                        var btn3 = '';
                        if (d.check_status == 0 || d.check_status == 3|| d.check_status == 4) {
                            btn1 = '<span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</span>';
                            btn2 = '<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>';
                            btn3 = '<span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="report">上报</span>';
                        }
                        var btn8 = '<span class="layui-btn  layui-btn-xs" lay-event="playback" style="background-color: #5fb878">收款管理</span>';
                        var btn9 = '<span class="layui-btn  layui-btn-xs" lay-event="payment"  style="background-color: #6C95F5">付款管理</span>';
                        var btn5 = '<span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view">查看</span>';
                        return html +  btn1 + btn2 + btn3 + btn5 + btn8+ btn9 +'</div>';
                    }
                }
                ]
            ]
        });

        //表头工具栏事件
        table.on('toolbar(test)', function (obj) {
            if (obj.event === 'add') {
                tool.side('/busine/businetransfer/add');
                return;
            }
            if (obj.event === 'LAYTABLE_EXCEL') {
                var formSelect = form.val('barsearchform');
                formSelect.limit = 99999;
                $.ajax({
                    url: '/busine/businetransfer/index',
                    data: formSelect,
                    success: function (res) {
                        table.exportFile('test', res.data, 'xls');
                    }
                });
                return;
            }
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;

            if (obj.event === 'edit') {
                tool.side('/busine/businetransfer/add?id=' + data.id);
                return;
            }
            if (obj.event === 'report') {
                tool.side('/busine/businetransfer/report?id=' + data.id);
                return;
            }
            if (obj.event === 'view') {
                tool.side('/busine/businetransfer/view?id=' + data.id);
                return;
            }

            if (obj.event === 'payment') {
                tool.side('/busine/businetransfer/payment?transfer_id=' + data.id);
                return;
            }

            if (obj.event === 'playback') {
                tool.side('/busine/businetransfer/playback?transfer_id=' + data.id);
                return;
            }

            if (obj.event === 'del') {
                layer.confirm('确定要删除吗?', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    }
                    tool.delete("/busine/businetransfer/delete", {id: data.id}, callback);
                    layer.close(index);
                });
            }
        });

        //选择合同性质
        var table_a;


        //选择母合同
        var table_b;


        //监听搜索提交
        form.on('submit(webform)', function (data) {
            layui.pageTable.reload({
                where: {
                    keywords: data.field.keywords,
                    cate_id: data.field.cate_id,
                    type: data.field.type,
                    check_status: data.field.check_status
                },
                page: {
                    curr: 1
                }
            });
            return false;
        });
    }
</script>
{/block}
<!-- /脚本 -->
